<template>
  <div class="detail">
    <!-- 头部 -->
    <headers :title="title"></headers>
    <!-- 房屋图片 -->
    <div class="house-detail-slides">
      <van-swipe :autoplay="3000" class="swipes">
        <van-swipe-item
          v-for="(item, index) in housingDetails.houseImg"
          :key="index"
          @click="previewImg(index)"
        >
          <img :src="imgBase + item" class="house-detail-slides-img" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 信息 -->
    <house-detail-info :housingDetails="housingDetails"></house-detail-info>
    <!-- 地图 -->
    <div class="house-detail-map">
      <div class="map-title">
        小区：<span class="map-title-span">天山星城</span>
      </div>
      <div class="map-container">
        <baidu-map
          class="bm-view"
          :center="center"
          :zoom="zoom"
          @ready="handler"
        >
          <bm-navigation anchor="BMAP_ANCHOR_BOTTOM_RIGHT"></bm-navigation>
        </baidu-map>
      </div>
    </div>
    <!-- 房屋配置 -->
    <detail-about :supporting="supporting"></detail-about>
    <!-- 房源概况 -->
    <detail-set></detail-set>
    <!-- 猜你喜欢 -->
    <recommend></recommend>
    <!-- 底部 -->
    <div class="house-detail-fixed-bottom">
      <detail-bottom></detail-bottom>
    </div>
  </div>
</template>

<script>
import Headers from '@/components/Headers.vue'
import Recommend from './components/Recommend.vue'
import DetailBottom from './components/DetailBottom.vue'
import DetailSet from './components/DetailSet.vue'
import DetailAbout from './components/DetailAbout.vue'
import HouseDetailInfo from './components/HouseDetailInfo.vue'
import { housesIdAPI } from '@/api'
import { ImagePreview } from 'vant'
export default {
  name: 'Detail',
  components: {
    Headers,
    Recommend,
    DetailBottom,
    DetailSet,
    DetailAbout,
    HouseDetailInfo
  },
  data() {
    return {
      imgBase: 'http://liufusong.top:8080',
      housingDetails: {},
      title: '',
      supporting: [],
      center: { lng: 0, lat: 0 },
      zoom: 3
    }
  },
  computed: {},
  created() {
    this.housesId()
  },
  methods: {
    // 查询房屋信息
    async housesId() {
      const { body } = await housesIdAPI(this.$route.params.houseCode)
      this.housingDetails = body
      this.title = body.community
      this.supporting = body.supporting
      this.ln = body.coord
    },
    // 地图
    handler() {
      setTimeout(() => {
        this.center.lng = this.ln.longitude
        this.center.lat = this.ln.latitude
      }, 5000)
      this.zoom = 15
    },
    // 图片预览
    previewImg(index) {
      const images = []
      this.housingDetails.houseImg.forEach((item) => {
        images.push(this.imgBase + item)
      })
      ImagePreview({
        images,
        startPosition: index,
        closeable: true
      })
    }
  }
}
</script>

<style scoped lang="less">
.detail {
  padding-bottom: 50px;
  background-color: #f6f5f6;
}
// 房屋图片
.house-detail-slides {
  height: 252px;
  .swipes {
    height: 211px;
    .house-detail-slides-img {
      width: 100%;
    }
    .van-swipe__indicators {
      bottom: 4px;
      .van-swipe__indicator {
        height: 8px;
        width: 8px;
        background-color: #ccc;
        margin: 0 3px;
      }
      .van-swipe__indicator--active {
        background-color: #888;
      }
    }
  }
}
// 地图
:deep(.house-detail-map) {
  margin-top: 10px;
  background: #fff;
  .map-title {
    font-size: 14px;
    margin: 0 3%;
    line-height: 44px;
    color: #666;
    .map-title-span {
      color: #333;
    }
  }
  .map-container {
    .bm-view {
      width: 100%;
      height: 145px;
    }
  }
}
// 底部
.house-detail-fixed-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  line-height: 50px;
}
</style>
